import com.mongodb.MongoClient;
import com.mongodb.client.FindIterable;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import org.bson.Document;

import javax.swing.text.html.FormSubmitEvent;

/**
 * @Author:zimmor
 * @Date: 2021/3/4 16:25
 * @Description
 * @version: 1.0.0
 */

public class MongoDbDemo1 {
    public static void main(String[] args) {
        //获取mongoDB的客户端
        MongoClient client = new MongoClient("192.168.204.128");
//        MongoClient client = new MongoClient("127.0.0.1");
        //获取数据库
        MongoDatabase db = client.getDatabase("spitdb");
        //获取collection
        MongoCollection<Document> spit = db.getCollection("spit");
        //然后操作collection
        FindIterable<Document> documents = spit.find();
        for (Document document: documents) {
//            System.out.println(document.getString("_id"));
            System.out.println(document.getString("content"));
            System.out.println(document.getInteger("visits"));

        }
        client.close();
        //关闭客户端连接

    }
}
